package com.dashu.core.controller;


import com.dashu.base.enums.ReplRyCode;
import com.dashu.core.dto.PageDTO;
import com.dashu.core.dto.gate.GateRuleDTO;
import com.dashu.core.dto.gate.GateRuleListDTO;
import com.dashu.core.dto.gate.GateTimeDTO;
import com.dashu.core.model.GateInTime;
import com.dashu.core.model.GateOutTime;
import com.dashu.core.result.PageEnty;
import com.dashu.core.result.ResultBean;
import com.dashu.core.service.GateInTimeService;
import com.dashu.core.service.GateOutTimeService;
import com.dashu.core.service.GateRuleService;
import com.dashu.core.vo.UpdateEntityVO;
import com.dashu.core.vo.gate.GateRuleListVO;
import com.dashu.core.vo.gate.GateRuleVO;
import com.dashu.core.vo.gate.GateTimeListVO;
import com.dashu.core.vo.gate.GateTimeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @Author xys
 * @Date 2020/ReplRyCode.SUCCESS.getCode()ReplRyCode.SUCCESS.getCode()/ReplRyCode.SUCCESS.getCode()7 ReplRyCode.SUCCESS.getCode()5:2ReplRyCode.SUCCESS.getCode()
 */

@RequestMapping("dashu/gate")
@RestController
@Slf4j
@Api(value = "dashu/gate", tags = {"闸机模块"}, description = "后台")
public class GateController {

    @Autowired
    private GateRuleService gateRuleService;
    @Autowired
    private GateInTimeService gateInTimeService;
    @Autowired
    private GateOutTimeService gateOutTimeService;
//    @Autowired
//    RestTemplate restTemplate;

    @PostMapping("/addRule")
    @ApiOperation(value = "闸机规则添加", notes = "闸机规则添加")
    public ResultBean<GateRuleDTO> addRule(@RequestBody @Validated GateRuleVO gateRuleVO) {
        return new ResultBean<>(ReplRyCode.SUCCESS.getCode(), "闸机规则添加", gateRuleService.add(gateRuleVO));
    }

    @PostMapping("/updataRule")
    @ApiOperation(value = "闸机规则信息修改", notes = "闸机规则信息修改")
    public ResultBean<GateRuleDTO> updataCls(@RequestBody @Validated UpdateEntityVO<GateRuleVO> updateGatekRuleVO) throws Exception {
        return new ResultBean<>(ReplRyCode.SUCCESS.getCode(), "闸机规则信息修改", gateRuleService.updataByGateRuleId(updateGatekRuleVO));
    }


    @DeleteMapping("/deleteRule")
    @ApiOperation(value = "删除闸机规则信息", notes = "删除闸机规则信息")
    public ResultBean<Boolean> deleteRule(long gatekRuleId) throws Exception {
        return new ResultBean<>(ReplRyCode.SUCCESS.getCode(), "删除闸机规则信息", gateRuleService.deleteByGateRuleId(gatekRuleId));

    }

    @PostMapping("/findRule")
    @ApiOperation(value = "闸机规则信息查询", notes = "闸机规则信息查询")
    public ResultBean<GateRuleDTO> findRule(long gatekRuleId) {
        return new ResultBean<>(ReplRyCode.SUCCESS.getCode(), "闸机规则信息查询", gateRuleService.findByGateRuleId(gatekRuleId));

    }

    @PostMapping("/findRuleList")
    @ApiOperation(value = "闸机规则信息查询", notes = "闸机规则信息查询")
    public ResultBean<PageDTO<GateRuleListDTO>> findRuleList(@RequestBody @Validated PageEnty<GateRuleListVO> rulePageEntyListVO) {
        PageDTO<GateRuleListDTO> pageDTO = new PageDTO<>();
        long total = gateRuleService.ruleListCount(rulePageEntyListVO);
        pageDTO.setTotal(total);
        pageDTO.setDataList(gateRuleService.pageGateRuleList(rulePageEntyListVO));
        return new ResultBean<>(ReplRyCode.SUCCESS.getCode(), "闸机规则信息查询", pageDTO);

    }


    @PostMapping("/addTime")
    @ApiOperation(value = "时间组添加", notes = "时间组添加")
    public ResultBean<GateTimeDTO> addTime(@RequestBody @Validated GateTimeVO gateTimeVO) {
        return new ResultBean<>(ReplRyCode.SUCCESS.getCode(), "时间组添加", gateRuleService.addTime(gateTimeVO));
    }

    @PostMapping("/updataTime")
    @ApiOperation(value = "时间组信息修改", notes = "时间组信息修改")
    public ResultBean<GateTimeDTO> updataTime(@RequestBody @Validated UpdateEntityVO<GateTimeVO> gateTimeEntityVO) throws Exception {
        return new ResultBean<>(ReplRyCode.SUCCESS.getCode(), "时间组信息修改", gateRuleService.updataByGateTime(gateTimeEntityVO));
    }


    @DeleteMapping("/deleteTime")
    @ApiOperation(value = "删除时间组信息", notes = "删除时间组信息")
    public ResultBean<Boolean> deleteTime(long timeId) throws Exception {
        return new ResultBean<>(ReplRyCode.SUCCESS.getCode(), "删除时间组信息", gateRuleService.deleteByGateTime(timeId));

    }

    @PostMapping("/findTime")
    @ApiOperation(value = "时间组信息查询", notes = "时间组信息查询")
    public ResultBean<GateTimeDTO> findTime(long timeId) throws Exception {
        return new ResultBean<>(ReplRyCode.SUCCESS.getCode(), "时间组信息查询", gateRuleService.findByGateTime(timeId));

    }

    @PostMapping("/findTimeList")
    @ApiOperation(value = "时间组信息查询", notes = "时间组信息查询")
    public ResultBean<PageDTO<GateTimeDTO>> findTimeList(@RequestBody @Validated PageEnty<GateTimeListVO> timeListVO) throws Exception {
        PageDTO<GateTimeDTO> pageDTO = new PageDTO<>();
        long total = gateRuleService.countTime(timeListVO);
        pageDTO.setTotal(total);
        pageDTO.setDataList(gateRuleService.pageGateTimeList(timeListVO));
        return new ResultBean<>(ReplRyCode.SUCCESS.getCode(), "时间组信息查询", pageDTO);

    }


}
